//
//  Pause.m
//  firstllk
//
//  Created by Huang Michael on 10-01-05.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "PausePage.h"
#import "mainpage.h"
#import "SimpleAudioEngine.h"

@implementation PausePage

- (id) init
{
	self = [super init];
	if (!self) {
		return nil;
	}
	
	//设置背景图
	CCSprite *spBg = [CCSprite spriteWithFile:@"pauseBg.png"];
	spBg.anchorPoint = CGPointZero;
	[self addChild:spBg z:0 tag:1];
	
	//添加菜单项
	CCSprite *spMainMenu = [CCSprite spriteWithFile:@"pauseBgMain.png"];	
	CCMenuItem *miMainMenu = [CCMenuItemSprite itemFromNormalSprite:spMainMenu selectedSprite:spMainMenu target:self selector:@selector(toMainMenu:)];
	
	CCSprite *spResume = [CCSprite spriteWithFile:@"pauseBgResume.png"];
	CCMenuItem *miResume = [CCMenuItemSprite itemFromNormalSprite:spResume selectedSprite:spResume target:self selector:@selector(resumeGame:)];
	
	
	CCMenu *mPause = [CCMenu menuWithItems:miResume, miMainMenu, nil];
	//设置菜单项对齐模式
	[mPause alignItemsVertically];
	
	// ask director the the window size
	CGSize size = [[CCDirector sharedDirector] winSize];
	mPause.position = ccp( size.width /2 , 180 );
	
	[self addChild:mPause z:1 tag:2];
	
	return self;
}

- (void) toMainMenu : (id) sender
{
#ifdef EN_SOUND	
	[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
#endif
	CCScene *sc = [CCScene node];
	[sc addChild:[mainpage node]];	
	[[CCDirector sharedDirector] replaceScene:  [CCTurnOffTilesTransition transitionWithDuration:0.5f scene:sc]];	
	
}

- (void) resumeGame : (id) sender
{
	[[CCDirector sharedDirector] popScene];

}


@end
